<?php
$script = "
var editor = CodeMirror.fromTextArea('".CHtml::getActiveId($model, 'dtd')."', {
    height: '350px',
    parserfile: 'parsexml.js',
    stylesheet: '".Yii::app()->theme->baseUrl."/scripts/CodeMirror/css/xmlcolors.css',
    path: '".Yii::app()->theme->baseUrl."/scripts/CodeMirror/js/',
    continuousScanning: 500,
    lineNumbers: true
});
";
Yii::app()->clientScript->registerScript(__CLASS__.'#InitXMLEditor', $script, CClientScript::POS_READY);
Yii::app()->clientScript->registerScriptFile(Yii::app()->theme->baseUrl.'/scripts/CodeMirror/js/codemirror.js');

$script = "
jQuery('#WidgetDefinition_type').change(function(){
    if (jQuery.inArray(parseInt(jQuery(this).val()), [".WidgetDefinition::TYPE_REQUIRED.",".WidgetDefinition::TYPE_STATIC."]) > -1)
    {
        jQuery('#WidgetDefinition_container').closest('.row').show();
    }
    else
        jQuery('#WidgetDefinition_container').closest('.row').hide();
});
jQuery('#WidgetDefinition_type').trigger('change');


jQuery('#WidgetDefinition_container').change(function(){
    var container = jQuery(this).val();
    if (jQuery.inArray(container, ['cms-header','cms-footer']) == -1)
    {
        if (container == 'custom')
            jQuery('#WidgetDefinition_containerCustom').show();
    }
    else
    {
        jQuery('#WidgetDefinition_containerCustom').hide();
    }
});
jQuery('#WidgetDefinition_container').trigger('change');
";
Yii::app()->clientScript->registerScript(__CLASS__.'#ShowContainer', $script, CClientScript::POS_READY);
?>
<style type="text/css">
  .CodeMirror-line-numbers {
    width: 2.2em;
    color: #aaa;
    background-color: #eee;
    text-align: right;
    padding-right: .3em;
    font-size: 10pt;
    font-family: monospace;
    padding-top: .4em;
    line-height: normal;
  }
</style>
<div class="form wide">

<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'widget-definition-form',
	'enableAjaxValidation'=>false,
)); ?>

	<p class="note">Fields with <span class="required">*</span> are required.</p>

	<?php //echo $form->errorSummary($model); ?>

    <?php if (! $model->IsNewRecord) echo $form->hiddenField($model, "id") ; ?>
	<div class="row">
		<?php echo $form->labelEx($model,'name'); ?>
		<?php echo $form->textField($model,'name',array('size'=>60,'maxlength'=>100)); ?>
		<?php echo $form->error($model,'name'); ?>
	</div>

    <div class="row">
        <?php echo $form->labelEx($model,'dtd', array('label'=>'DTD')); ?>
        <?php echo $form->error($model,'dtd'); ?>
    </div>
    <div class="row" style="border: 1px solid black; margin-left: 210px;">
        <?php echo $form->textArea($model,'dtd',array('cols'=>70, 'rows'=>7, 'encode'=>true)); ?>
    </div>

	<div class="row">
		<?php echo $form->labelEx($model,'description'); ?>
        <?php echo $form->textArea($model,'description',array('cols'=>70, 'rows'=>7)); ?>
    </div>

    <div class="row">
        <?php echo $form->labelEx($model,'status', array('label'=>'Active')); ?>
        <?php echo $form->checkBox($model,'status'); ?>
        <?php echo $form->error($model,'status'); ?>
    </div>

    <div class="row">
        <?php echo $form->labelEx($model,'type'); ?>
        <?php echo $form->dropDownList($model,'type', $model->typeOptions); ?>
        <?php echo $form->error($model,'type'); ?>
    </div>

	<div class="row">
		<?php echo $form->labelEx($model, 'container'); ?>
        <?php echo $form->dropDownList($model, 'container', array('cms-header'=>'Header','cms-footer'=>'Footer','custom'=>'Custom'), array('prompt'=>'---Select---'));?>
		<?php echo $form->textField($model,'containerCustom',array('size'=>60,'maxlength'=>100,'style'=>'display:none;')); ?>
		<?php echo $form->error($model,'container'); ?>
	</div>

	<?php if ($model->isNewRecord == false):?>
    <div class="row">
        <?php echo $form->labelEx($model,'creation_datetime'); ?>
        <?php echo Yii::app()->getDateFormatter()->formatDateTime(strtotime($model->creation_datetime)); ?>
    </div>

    <div class="row">
        <?php echo $form->labelEx($model,'last_update'); ?>
        <?php echo Yii::app()->getDateFormatter()->formatDateTime(strtotime($model->last_update)); ?>
    </div>
    <?php endif;?>

	<div class="row buttons">
		<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
        <?php echo CHtml::link('Delete', array('delete', 'id'=>$model->id), array('confirm'=>'Are you sure you want to delete this widget?', 'submit'=>$this->createUrl('delete', array('id'=>$model->id))));?>
	</div>

<?php $this->endWidget(); ?>

</div><!-- form -->